#ifndef TC_SHUFFLE_HH
#define TC_SHUFFLE_HH

/** \file Shuffle.hh 
 * Declarations for the Random number generator.
 *
 * (c) Copyright  Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: Random.hh 119 2006-06-21 04:57:25Z semihc $
 *
 *
 */

#include <stdlib.h>

namespace TC {

/**
 * Shuffling (generating a random permutation) algorithm
 * based on Fisher-Yates shuffle.
 */
template <typename T>
void Shuffle(T array[], unsigned n)
{
  if (n < 1) return;
  
  for (unsigned i=0; i < n-1; i++) {
    unsigned j = i + rand() / (RAND_MAX / (n - i) + 1);
    T t = array[j];
    array[j] = array[i];
    array[i] = t;
  }
}


} // end namespace



#endif /* Include guard */
